#!/usr/bin/env python
# vim:fileencoding=utf-8
from calibre.web.feeds.news import BasicNewsRecipe, classes


class Digit(BasicNewsRecipe):
    title = u'Digit Magazine'
    description = 'Digit caters to the largest community of tech buyers, users and enthusiasts in India.'
    language = 'en_IN'
    __author__ = 'unkn0wn'
    oldest_article = 30  # days
    max_articles_per_feed = 50
    encoding = 'utf-8'
    use_embedded_content = False
    no_stylesheets = True
    masthead_url = 'https://www.digit.in/images/digit_logo.png'
    remove_attributes = ['style', 'height', 'width']
    ignore_duplicate_articles = {'title', 'url'}

    def get_cover_url(self):
        soup = self.index_to_soup(
            'https://store.digit.in/cart.php?category_id=139&year='
        )
        tag = soup.find(attrs={'class': 'previous-magazines'})
        if tag:
            self.cover_url = tag.find('img')['src']
        return super().get_cover_url()

    keep_only_tags = [
        classes(
            'big_img_container highlights_cont Top-sponsered Text-sponsered heading-wraper article_video'
            'article-inside-container skoar_desc New-desk pros-Cons Review-reting For-table col-md-7'
            'review-inside-container price_wrap key_specifications'
        ),
    ]

    remove_tags = [
        classes(
            'adsAdvert Video-wraper article_share auth_social breadcrumbwrap textads_list rel_articles_container'
        ),
    ]

    feeds = [
        ('Features', 'http://feeds.feedburner.com/digit/latest-features'),
        ('Reviews', 'http://feeds.feedburner.com/digit/latest-review'),
        ('Laptops', 'https://feeds.feedburner.com/digit/latest-laptops'),
        ('PC Components', 'https://feeds.feedburner.com/digit/latest-pc-components'),
        ('Tablets', 'https://feeds.feedburner.com/digit/latest-tablets'),
        ('TVs', 'https://feeds.feedburner.com/digit/latest-tvs'),
        (
            'Wearable devices',
            'https://feeds.feedburner.com/digit/latest-wearable-devices'
        ),
        ('How-to', 'https://feeds.feedburner.com/digit/how-to'),
        ('Entertainment', 'https://feeds.feedburner.com/digit/latest-entertainment'),
        ('Gaming', 'http://feeds.feedburner.com/digit/latest-gaming'),
        ('Software', 'https://feeds.feedburner.com/digit/latest-software'),
        ('Audio-Video', 'https://feeds.feedburner.com/digit/latest-audio-video'),
        # ('Apps', 'https://feeds.feedburner.com/digit/latest-apps'),
        # ('Mobile Phones', 'https://feeds.feedburner.com/digit/latest-mobile-phones'),
        # For more : https://www.digit.in/rss-feed/
    ]
